package yxy.game.pm2.bean.db.sdk;

import yxy.apple.database.BaseDAO;
import yxy.apple.database.DAOSDKManager;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;
//融合渠道配置表
public class SDK_UnionChannelDAO extends BaseDAO<SDK_UnionChannel> {

	//专服里的用户
	public static SDK_UnionChannel getByAppId(String channel, String appId) {
		try {
			Map<String, Object> params = new Hashtable<>();
			params.put("channel", channel);
			params.put("app_id", appId);

			String sql = "select * from union_channel where `channel`=:channel and app_id=:app_id limit 1";
			List<SDK_UnionChannel> list = queryBySql(DAOSDKManager.getGameH(), SDK_UnionChannel.class, sql, params);
			return (list != null && list.size() > 0) ? list.get(0) : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	//专服里的用户
	public static SDK_UnionChannel getByAppKey(String channel, String appKey) {
		try {
			Map<String, Object> params = new Hashtable<>();
			params.put("channel", channel);
			params.put("app_key", appKey);

			String sql = "select * from union_channel where `channel`=:channel and app_key=:app_key limit 1";
			List<SDK_UnionChannel> list = queryBySql(DAOSDKManager.getGameH(), SDK_UnionChannel.class, sql, params);
			return (list != null && list.size() > 0) ? list.get(0) : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	//专服里的用户
	public static SDK_UnionChannel getByChannel(int clusterId, String channel) {
		try {
			Map<String, Object> params = new Hashtable<>();
			params.put("cluster_id", clusterId);
			params.put("channel", channel);

			String sql = "select * from union_channel where `cluster_id`=:cluster_id and channel=:channel limit 1";
			List<SDK_UnionChannel> list = queryBySql(DAOSDKManager.getGameH(), SDK_UnionChannel.class, sql, params);
			return (list != null && list.size() > 0) ? list.get(0) : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static boolean add(SDK_UnionChannel db) {
		return SDK_UnionChannelDAO.add(DAOSDKManager.getGameH(), db);
	}

	public static boolean update(SDK_UnionChannel db) {
		return SDK_UnionChannelDAO.update(DAOSDKManager.getGameH(), db);
	}
}
